package org.neframework.webtest.action.xyk.doit;

import java.util.List;
import java.util.Map;

import org.neframework.webtest.base.BaseController;
import org.neframework.webtest.service.CustomerAnysisService;
import org.neframework.webtest.util.date.DateTools;

import com.tmsps.neframework.core.utils.ChkTools;
import com.tmsps.neframework.mvc.annotation.Controller;
import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.annotation.ResponseBody;

@Controller
@RequestMapping("/cp/xyk/doit/zd")
public class DoitZdController extends BaseController {

	private static final CustomerAnysisService anysisService = new CustomerAnysisService();

	@RequestMapping("/list")
	public String list() {
		String srh_date = DateTools.getToday();

		req.setAttribute("srh_date", srh_date);
		return "/jsp/xyk/doit/zd/list.jsp";
	}

	@RequestMapping("/list_data")
	@ResponseBody
	public void list_data(String srh_date) {
		if (ChkTools.isNull(srh_date)) {
			srh_date = DateTools.getToday();
		}

		List<Map<String, Object>> list = anysisService.selectDoitZdList(
				srh_date, sort_params, page);
		// 查询流水
		for (Map<String, Object> map : list) {
			String customer_card_id = (String) map.get("kid");
			Map<String, Object> flowMap = anysisService.findFlowMap(
					customer_card_id, srh_date);
			map.putAll(flowMap);

			// 计算距离最后还款日
			int bill_back_day = (int) map.get("bill_back_day");
			int bill_back_day_end = DateTools.countDaysByToday(bill_back_day);

			map.put("bill_back_day_end", bill_back_day_end);
		}

		result.put("list", list);
	}

}
